<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加班级</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="./css/index.css">
		<link rel="stylesheet" href="./layui/css/layui.css" />
</head>
<body>

 <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 0 0 0;">
	     <div class="layui-form-item">
	        <label class="layui-form-label">用户名</label>
	        <div class="layui-input-inline">
	           <input type="text" id="userid" name="userid" lay-verify="userid" value="${loginuser.userid }" readonly="readonly" style="background-color: #F5F5F5;" placeholder="用户名不能为空" autocomplete="off" class="layui-input">
	        </div>
	     </div>
	     <div class="layui-form-item">
	       <label class="layui-form-label">真实姓名</label>
	       <div class="layui-input-inline">
	          <input type="text" id="realname" name="realname" lay-verify="realname" value="${loginuser.realname }" readonly="readonly" style="background-color: #F5F5F5;" autocomplete="off" class="layui-input">
	       </div>
	     </div>
	     <div class="layui-form-item">
	       <label class="layui-form-label">原始密码</label>
	       <div class="layui-input-inline">
	          <input type="password" id="oldpwd" name="oldpwd" lay-verify="oldpwd" placeholder="请输入原始密码" autocomplete="off" class="layui-input">
	       </div>
	     </div>
	     <div class="layui-form-item">
	       <label class="layui-form-label">新密码</label>
	       <div class="layui-input-inline">
	          <input type="password" id="newpwd" name="newpwd" lay-verify="newpwd" placeholder="请输入新密码" autocomplete="off" class="layui-input">
	       </div>
	     </div>
	     <div class="layui-form-item">
	       <label class="layui-form-label">确认密码</label>
	       <div class="layui-input-inline">
	          <input type="password" id="confirmpwd" name="confirmpwd" lay-verify="confirmpwd" placeholder="请再次确认新密码" autocomplete="off" class="layui-input">
	       </div>
	     </div>
	     
	     <div class="layui-form-item layui-hide">
	        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
	        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
	     </div>
  </div>

<script src="../js/jquery-3.3.1.js" charset="utf-8"></script>
<script src="../layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="../layui/layui.all.js" charset="utf-8"></script> 
<script src="../js/provincialLevel.js" charset="utf-8"></script>
<script src="../lib/md5.js" charset="utf-8"></script>
<script src="../lib/systempublickey.js" charset="utf-8"></script>

<script type="text/javascript">
 layui.use(['table','jquery','upload','form','laydate','layer'], function(){
  var table = layui.table;
  var $ = layui.jquery;
  var form=layui.form;
  var layer = layui.layer,laydate = layui.laydate,upload = layui.upload;
  
	  //执行一个laydate实例
	  laydate.render({
	    elem: '#starttime' //指定元素
	    ,trigger : 'click'
	  });
	  
	  laydate.render({
	    elem: '#endtime' //指定元素
	    ,trigger : 'click'
	  });
  
    //监听提交,添加事件
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
 			
		//获取参数，数据校验
		var userid = $("#userid").val().trim();
		var oldpwd = $("#oldpwd").val().trim();
		var newpwd = $("#newpwd").val().trim();	
		var confirmpwd = $('#confirmpwd').val().trim();
		if(oldpwd==""){
			layer.tips('不能为空', '#oldpwd');
			return;
		}
		if(newpwd==""){
			layer.tips('不能为空', '#newpwd');
			return;
		}
		if(newpwd==oldpwd){
			layer.tips('与旧密码一致，从新输入', '#newpwd');
			return;
		}
		if(newpwd.length<6 || newpwd.length>18){
			layer.alert('新密码长度不符合规范!', {icon: 2});
			return;
		}
		if(confirmpwd==""){
			layer.tips('不能为空', '#confirmpwd');
			return;
		}
		if(confirmpwd.length<6 || confirmpwd.length>18){
			layer.alert('确认密码长度不符合规范!', {icon: 2});
			return;
		}
		if(confirmpwd != newpwd) {
			layer.tips('密码不一致', '#confirmpwd');
			return;
		}
		
		/* 用MD5将密码做加密处理 */
		var oldenpwd = hex_md5(fix(userid,oldpwd));
		$("#user_password").val(oldenpwd);
		//alert(oldenpwd);
		
		/* 用MD5将密码做加密处理 */
		var enpwd = hex_md5(fix(userid,newpwd));
		$("#user_password").val(enpwd);
		//alert(enpwd);
		
		var param = "?oldpwd=" + oldenpwd + "&newpwd=" + enpwd;
		
		$.ajax({
			url:"../admin/modifyuserpwd" + param,
			type:"POST",
			data:null,
			dataType : "json",
			xhrFields :{
				withCredentials: true
			},
			contentType:'application/json;charset=UTF-8',
			success:function(e){
				//alert(e.msg)
				if(e.code == 0){
					layer.msg(e.msg,{icon:6}); 
				}else{
					layer.msg(e.msg,{icon:5});
				}
				
				setTimeout(function(){
						parent.layui.table.reload('LAY-app-content-list'); //重载表格
     					parent.layer.close(index); //再执行关闭 
				},1*1000)
				
			},
			error:function(e){
				layer.msg(e.msg,{icon:5});
			}
		})
   	return false;
  });
  
  
});
</script>
</body>
</html>